<?php
/*
 * ebiz front
 *
 * HeaderView
 *
 * @author allen
 *
 */
require_once '../app/services/ShoppingCartService.php';
require_once '../app/services/CustomerService.php';
require_once '../app/services/AAService.php';
require_once '../app/services/VoteService.php';

class HeaderView {

    public static function getCommonHeaderView(){
        $cartPath = "/u/cart";
        $checkoutPath = "/u/checkout";
        $loginPath = "/u/login";
        $registerPath = "/u/register";
        $logoutPath = "/o/logout";
    	$loginHeaderhtml = "";
        $shoppingcartService = new ShoppingcartService();
        $voteService = new VoteService();
        $totalOpinionNum = $voteService->getOpinionNumber(0);
        if(AAService::isLogin()){ //user already login
            $customerId = AAService::getCustomer();
            $result = $shoppingcartService->showItemAndTotalByCustomerId($customerId);    //set default customer id is '1'
            $customerService = new CustomerService();
            $resultUser = $customerService->getCustomerById($customerId);
            $customerName = $resultUser[0]['name'];
            $loginHeaderhtml .= "<li></li>";
            $loginHeaderhtml .= "<li style='text-align:right;width:150px;overflow:hidden;'><label title='".$customerName."'>". CommonUtil::cut_str($customerName, 10, 0) ."</label></li>";
            $loginHeaderhtml .= "<li onclick=\"window.location='{$logoutPath}';\" style='cursor:pointer;'> [退出] </li>";
        }else{
            $result = $shoppingcartService->showItemAndTotalFromCookie();
            $loginHeaderhtml .= "<li style='cursor:pointer;text-align:right;width:150px;' onclick=\"window.location='{$loginPath}';\" style='cursor:pointer;'>登录</li>";
            $loginHeaderhtml .= "<li>|</li>";
            $loginHeaderhtml .= "<li onclick=\"window.location='{$registerPath}';\" style='cursor:pointer;'>注册</li>";
        }
        $itemInfo = $result["item_info"];
        $cartHtml = "";
        if(!empty($itemInfo)){
        	$cartHtml .= "<ul id='cartGoods_gc' class='cartGoods_gc' style='display:none;'>";
	        foreach ($itemInfo as $item) {
	        	$cartHtml .= "<li>".$item["title"]." &nbsp;&nbsp; ￥".$item["sale_price"]."×".$item["quantity"]."</li>";
	        }
	        $cartHtml .= "<li><div class='DD_gc'>总价：￥<span id='topCartTotalPrice'>".$result[1]."</span></div></li>";
	        $cartHtml .= "<li style='border-bottom:1px solid #FFFFFF'>";
	        $cartHtml .= "<table>";
	        $cartHtml .= "<tr>";
	        $cartHtml .= "<td width='60' valign='middle' class='RedFont_gc'>合计<span id='topCartItemQty'>".$result[0]."</span>件&nbsp;&nbsp;&nbsp;</td>";
	        $cartHtml .= "<td width='215' valign='middle'>";
	        $cartHtml .= "<img src='". ConfigConstants::getTImagePath() ."/button_2.jpg' alt='进入结算中心' onclick=\"window.location='{$checkoutPath}';\" />&nbsp;";
	        $cartHtml .= "<img src='". ConfigConstants::getTImagePath() ."/button_1.jpg' alt='查看购物车' onclick=\"window.location='{$cartPath}';\" />";
	        $cartHtml .= "</td>";
	        $cartHtml .= "</tr>";
	        $cartHtml .= "</table>";
	        $cartHtml .= "</li>";
	        $cartHtml .= "</ul>";
        }else{
        	$cartHtml .= "<ul id='cartGoods_gc' class='cartGoods_gc' style='display:none;'>";
        	$cartHtml .= "<li>您的购物车中还没有商品，快来添加吧</li>";
        	$cartHtml .= "<li><div class='DD_gc'>总价：￥<span id='topCartTotalPrice'>0</span></div></li>";
        	$cartHtml .= "</ul>";
        }

        $myMimiInfo = "<ul id='myMimi_gc' class='myMimi_gc' style='display:none'>";
        $myMimiInfo .= "<li onclick=\"window.location='/userinfo/myorderlist';\">我的订单</li>";
        $myMimiInfo .= "<li onclick=\"window.location='/userinfo/myquery';\">我的咨询</li>";
//        $myMimiInfo .= "<li onclick=\"window.location='';\">我的举报</li>";
//        $myMimiInfo .= "<li onclick=\"window.location='';\">我的建议</li>";
//        $myMimiInfo .= "<li onclick=\"window.location='';\">我的投诉</li>";
//        $myMimiInfo .= "<li onclick=\"window.location='';\">我的晒单返现</li>";
        $myMimiInfo .= "<li onclick=\"window.location='/userinfo/delivery';\">查看收货地址</li>";
//        $myMimiInfo .= "<li onclick=\"window.location='';\">推荐高校代理</li>";
        $myMimiInfo .= "<li onclick=\"window.location='/u/cart';\">我的购物车</li>";
        $myMimiInfo .= "</ul>";

        $headerHtml =
<<<str_result

<script type='text/javascript'> 
//<![CDATA[
$("document").ready(function(){
    $("#searchWords").keypress(function(e){     
        if(e.which == 13){
            window.location='/s/' + $('#searchWords').val();
        }
    }); 
});    
//]]> 
</script>


<div class="layoutmain" style="width:970px;">
<!-- top begin -->
    <div class="akimi_top_gc">

        <div class="akimi_topleft_gc"  style="cursor:pointer;" onclick="window.location='/';">
            <div class="akimi_logo_gc"></div>
            <div class="akimi_topad_gc"></div>
        </div>

        <div class="akimi_topcenter_gc">
            <ul>
                <li onclick="window.location='/';">首页</li>
                <li>手机通讯
                <div class="akimi_nva_gc" id="menu_1" style="display:none; z-index:5;">
                    <ul style="BORDER-BOTTOM:#F1F1F1 1px dotted;">
                        <span class="nav1_gc"><a href="/c/index/mobile_and_accessories">手机</a></span>
                        <span class="nav1_gc" onclick="window.location='/c/index/m_cells'">手机电池</span>
                     </ul>
                     <ul>
                        <span class="nav2_gc"><a href="/c/index/mobile_and_accessories">手机</a></span>
                        <span class="nav3_gc" onclick="window.location='/c/search/21/83/5213'">诺基亚</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/21/83/5215'">摩托罗拉</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/21/83/5214'">三星</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/21/83/5216'">索尼爱立信</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/21/83/5224'">天语</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/21/83/5221'">联想</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/21/83/5217'">多普达</span>
                    </ul>
                     <ul>
                        <span class="nav2_gc" onclick="window.location='/c/search/28'">手机电池</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/28/3632/19673'">飞毛腿</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/28/3632/19677'">诺基亚</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/28/3632/19678'">摩托罗拉</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/28/3632/19679'">索尼爱立信</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/28/3632/19680'">三星</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/28/3632/19681'">多普达</span>
                    </ul>
                </div>
                </li>
                <li>数码百货
                <div class="akimi_nva_gc" id="menu_2" style="display:none; z-index:5;">
                    <ul style="BORDER-BOTTOM:#F1F1F1 1px dotted;">
                        <span class="nav1_gc" onclick="window.location='/c/index/dc_and_accessories'">数码相机</span>
                        <span class="nav1_gc" onclick="window.location='/c/index/household'">百货家电</span>
                        <span class="nav1_gc" onclick="window.location='/c/index/gift_trinket'">礼品</span>
                     </ul>
                    <ul>
                        <span class="nav2_gc" onclick="window.location='/c/index/dc_and_accessories'">数码相机</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/41/89/218'">佳能</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/41/89/221'">三星</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/41/89/220'">索尼</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/41/89/219'">尼康</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/41/89/228'">奥林巴斯</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/41/89/223'">松下</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/41/89/222'">柯达</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/41/89/227'">卡西欧</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/41/89/230'">明基</span>
                    </ul>
                     <ul>
                        <span class="nav2_gc" onclick="window.location='/c/index/household'">生活家电</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/55'">剃须刀</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/57'">电吹风</span>
                    </ul>
                     <ul>
                        <span class="nav2_gc" onclick="window.location='/c/index/gift_trinket'">礼品</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/160'">Zippo打火机</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/162'">瑞士军刀</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/164'">创意礼品</span>
                    </ul>
                </div>
                </li>
                <li>电脑产品
                <div class="akimi_nva_gc" id="menu_3" style="display:none; z-index:5;">
                    <ul style="border-bottom:#F1F1F1 1px dotted;">
                        <span class="nav1_gc" onclick="window.location='/c/index/notebook_and_accessories'">笔记本</span>
                        <span class="nav1_gc" onclick="window.location='/c/index/peripherals'">电脑配件</span>
                        <span class="nav1_gc" onclick="window.location='/c/search/155'">存储设备</span>
                     </ul>
                     <ul>
                        <span class="nav2_gc" onclick="window.location='/c/index/notebook_and_accessories'">笔记本</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/97/227/754'">联想</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/97/227/749'">ThinkPad</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/97/227/751'">宏碁</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/97/227/750'">华硕</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/97/227/748'">惠普</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/97/227/755'">苹果</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/97/227/752'">索尼</span>
                    </ul>

                     <ul>
                        <span class="nav2_gc" onclick="window.location='/c/index/peripherals'">电脑配件</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/137'">鼠标</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/159'">耳机</span>
                    </ul>
                     <ul>
                        <span class="nav2_gc" onclick="window.location='/c/search/155'">存储设备</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/155/3676/17902'">U盘</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/155/3676/17903'">SD卡</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/155/3676/17904'">TF卡</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/155/3676/17905'">CF卡</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/155/3676/17906'">记忆棒</span>
                    </ul>
                  </div>
                </li>
                <li>影音娱乐
                <div class="akimi_nva_gc" id="menu_4" style="display:none; z-index:5;">
                  <ul style="border-bottom:#F1F1F1 1px dotted;">
                        <span class="nav1_gc" onclick="window.location='/c/index/yui'">MP3/MP4</span>
                        <span class="nav1_gc" onclick="window.location='/c/index/dzcd'">电子词典</span>
                        <span class="nav1_gc" onclick="window.location='/c/search/159'">耳机</span>
                     </ul>
                     <ul>
                        <span class="nav2_gc" onclick="window.location='/c/search/171'">MP3/MP4</span>   
                        <span class="nav3_gc" onclick="window.location='/c/search/171/3297/16306'">艾利和</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/171/3297/16304'">IPOD</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/171/3297/16303'">OPPO</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/171/3297/16305'">纽曼</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/171/3297/17826'">爱国者</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/171/3297/16310'">台电</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/171/3297/16307'">飞利浦</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/171/3297/16308'">魅族</span>
                    </ul>
                    <ul>
                        <span class="nav2_gc" onclick="window.location='/c/search/173'">电子词典</span>   
                        <span class="nav3_gc" onclick="window.location='/c/search/173/3300/16312'">好易通</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/173/3300/16314'">快易典</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/173/3300/16316'">诺亚舟</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/173/3300/16317'">文曲星</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/173/3300/16311'">步步高</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/173/3300/16313'">卡西欧</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/173/3300/16315'">名人</span>
                    </ul>
                    <ul>
                        <span class="nav2_gc" onclick="window.location='/c/search/159'">耳机</span>   
                        <span class="nav3_gc" onclick="window.location='/c/search/159/3620/17825'">森海塞尔</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/159/3620/17827'">飞利浦</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/159/3620/17891'">铁三角</span>
                        <span class="nav3_gc" onclick="window.location='/c/search/159/3620/18017'">硕美科</span>
                    </ul>
                </div>
                </li>
            </ul>
            <!--<div class="akimi_topsearch_gc">
                
                <div style="float:left;margin-left:110px;*margin-left:50px;_margin-left:35px;">
	                <input type="text" value="请输入关键字" " class="s_input_gc" id="searchWords" />
	            </div>
	            <div style="float:left;margin-top:3px;cursor:pointer;" onclick="javascript:window.location='/s/' + $('#searchWords').val();">    
	                <img id='submitSearchBtn' src='//i.ebiz-interactive.info/t/default_zh_cn/image/searchbtn_bg.png' alt='' style='height:21px;*height:24px;_height:24px;' />
                </div>    
                <div class="clear"></div>           
            </div>-->
            
	    <div class="akimi_topsearch">
	        <input type="text" value="请输入关键字" class="s_input" id="searchWords"  /><!--onkeydown="javascript:submitSearch();"-->
	        <input type="button" value="搜索" class="s_btn" id='submitSearchBtn' onclick="javascript:window.location='/s/' + $('#searchWords').val();"/>
	    </div>
	    
        </div>

        <div class="akimi_topright_gc" style='_position:absolute;_top:0px;margin-left:-120px;'>
            <ul class="akimi_toprightul01_gc" style="margin-left:10px;_margin-left:55px;">

            $loginHeaderhtml

                <li>|</li>
                <li style='cursor:pointer;' onclick="window.location='/u/help?type=buyprocess';">购物帮助</li>

            </ul>
            <ul class="akimi_toprightul02_gc" style="margin-left:60px;_margin-left:85px;">
                <li class="myCart_gc" id="cartId">
                    <a class="cart_gc" href="/u/cart" style='text-decoration: none; color: rgb(118, 167, 58);'>我的购物车</a>

                    $cartHtml

                    <!--
                    <ul id='cartGoods_gc' class="cartGoods_gc" style="display:none;">
                        <li>诺基亚  2610  移动定制机 ￥275.00 ×1</li>
                                <li><div class="DD_gc">总价：￥<span id='topCartTotalPrice'>1200</span></div></li>
                        <li style="border-bottom:1px solid #FFFFFF">
                            <table>
                            <tr>
                            <td width="60" valign="middle" class="RedFont_gc">合计<span id='topCartItemQty'>1</span>件&nbsp;&nbsp;&nbsp;</td>
                            <td width="215" valign="middle">
                                <img onclick="window.location='/u/cart';" src="<?php echo ConfigConstants::getTImagePath(); ?>/button_2.jpg" alt="进入结算中心"/>&nbsp;
                                <img onclick="window.location='/u/checkout';" src="<?php echo ConfigConstants::getTImagePath(); ?>/button_1.jpg" alt="查看购物车" />
                            </td>
                            </tr>
                            </table>
                        </li>
                    </ul>
                        -->

                </li>
                <li class="myakimi_gc" id="aKimimi">
                    <a href="/userinfo/index" style='text-decoration: none; color: rgb(118, 167, 58);'>我的阿基米米</a>

                    $myMimiInfo

                    <!--
                    <ul id='myMimi_gc' class="myMimi_gc" style="display:none">
                        <li>我的订单</li>
                        <li>我的咨询</li>
                        <li>我的举报</li>
                        <li>我的建议</li>
                        <li>我的投诉</li>
                        <li>我的晒单返现</li>
                        <li>我的咨询管理</li>
                        <li>查看收货地址</li>
                        <li>推荐高校代理</li>
                        <li>我的购物车</li>
                        <li>我的订单</li>
                    </ul>
                    -->

                </li>

            </ul>
            <div class="akimi_toprightdiv_gc"><a href="#" onclick="window.location='/u/showallopinion'">查看客户评价<span>{$totalOpinionNum}</span>条</a></div>

        </div>

    </div>
    <!-- top end -->
</div>

str_result;

        return $headerHtml;

    }


}

